public class Text {
    public String addBinary(String a, String b) {
        int lenA = a.length()-1;
        int lenB = b.length()-1;
        StringBuilder str = new StringBuilder();
        int carry = 0;
        int maxlen = Math.max(lenA,lenB);
        for(int i = 0;i <= maxlen;i++) {
            int daita = i < a.length() ? (a.charAt(lenA - i) - '0'):0;
            int daitb = i < b.length() ? (b.charAt(lenB - i) - '0'):0;
            int sum = daita+daitb+carry;
            carry = sum >= 2 ? 1 : 0;
            sum = sum>=2 ? sum%2:sum;
            str.append(sum);
        }
        if(carry > 0) {
            str.append('1');
        }
        str.reverse();
        return str.toString();
    }
}
